package com.htc.utils;

import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory;
import android.util.Base64;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.Locale;
import java.util.Random;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CommonObjects {

	public static final String APP_NAME_TAG = "HRMS LOG";
	public static final String DATA = "data";
	public static final String DEVICE_TYPE = "1";
	public static final String ERROR = "error";
	public static final String MESSAGE = "message";
	public static final String STATUS = "status";
	public static boolean ShortCut_leave_tomorow;
	public static boolean ShortCut_leave_yesterday;
	public static boolean ShortCut_permission_early;
	public static boolean ShortCut_permission_late;

	public static String checkEndDate(String paramString1, String paramString2) {
		String str1 = "";
		try {
			SimpleDateFormat localSimpleDateFormat1 = new SimpleDateFormat(
					"MM-dd-yyyy", Locale.ENGLISH);
			SimpleDateFormat localSimpleDateFormat2 = new SimpleDateFormat(
					"yyyy-MM-dd", Locale.ENGLISH);
			String str2 = localSimpleDateFormat2.format(localSimpleDateFormat1
					.parse(paramString1));
			String str3 = localSimpleDateFormat2.format(localSimpleDateFormat1
					.parse(paramString2));
			Date localDate1 = localSimpleDateFormat2.parse(str3);
			Date localDate2 = localSimpleDateFormat2.parse(str2);
			System.out.println(localSimpleDateFormat2.format(localDate1));
			System.out.println(localSimpleDateFormat2.format(localDate2));
			if (localDate1.after(localDate2)) {
				System.out.println("end_date1 is after start_date2");
				str1 = "after";
			}
			if (localDate1.before(localDate2)) {
				System.out.println("end_date1 is before start_date2");
				str1 = "before";
			}
			if (localDate1.equals(localDate2)) {
				System.out.println("end_date1 is equal start_date2");
				str1 = "today";
			}
			return str1;
		} catch (ParseException localParseException) {
			localParseException.printStackTrace();
		}
		return str1;
	}

	public static String getBitmapFromURL(String paramString) {
		try {
			ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
			HttpURLConnection localHttpURLConnection = (HttpURLConnection) new URL(
					paramString).openConnection();
			localHttpURLConnection.setDoInput(true);
			localHttpURLConnection.connect();
			BitmapFactory.decodeStream(localHttpURLConnection.getInputStream())
					.compress(Bitmap.CompressFormat.JPEG, 100,
							localByteArrayOutputStream);
			String str = new String(Base64.encode(
					localByteArrayOutputStream.toByteArray(), 0), "UTF-8");
			return str;
		} catch (IOException localIOException) {
			localIOException.printStackTrace();
		}
		return null;
	}

	public static Bitmap getBitmapImg(String paramString) {
		try {
			byte[] arrayOfByte = Base64.decode(paramString, 0);
			Bitmap localBitmap = BitmapFactory.decodeByteArray(arrayOfByte, 0,
					arrayOfByte.length);
			return localBitmap;
		} catch (Exception localException) {
		}
		return null;
	}

	public static String getCalendarDate(String paramString) {
		String str1 = paramString.substring(0, 2);
		String str2 = paramString.substring(2, 4);
		String str3 = paramString.substring(4, 8);
		String str4 = str3 + "-" + str2 + "-" + str1;
		return str4;
	}

	public static String getCurrentDate() {
		SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat(
				"yyyy-MM-dd", Locale.ENGLISH);
		Calendar localCalendar = Calendar.getInstance();
		System.out
				.println(localSimpleDateFormat.format(localCalendar.getTime()));
		return localSimpleDateFormat.format(localCalendar.getTime());
	}

	public static String getCurrentYear() {
		int i = Calendar.getInstance().get(1);
		String str = String.valueOf(i);
		return str;
	}

	public static int getDaysDifferece(String paramString1, String paramString2) {
		int i = 0;
		try {
			SimpleDateFormat localSimpleDateFormat1 = new SimpleDateFormat(
					"MM-dd-yyyy", Locale.ENGLISH);
			SimpleDateFormat localSimpleDateFormat2 = new SimpleDateFormat(
					"yyyy-MM-dd", Locale.ENGLISH);
			String str1 = localSimpleDateFormat2.format(localSimpleDateFormat1
					.parse(paramString1));
			String str2 = localSimpleDateFormat2.format(localSimpleDateFormat1
					.parse(paramString2));
			Date localDate1 = localSimpleDateFormat2.parse(str2);
			Date localDate2 = localSimpleDateFormat2.parse(str1);
			i = (int) ((localDate1.getTime() - localDate2.getTime()) / 86400000L);
			return i;
		} catch (ParseException localParseException) {
			localParseException.printStackTrace();
		}
		return i;
	}

	public static String getGMTDate(String paramString) {
		SimpleDateFormat localSimpleDateFormat1 = new SimpleDateFormat(
				"MM-dd-yyyy", Locale.ENGLISH);
		SimpleDateFormat localSimpleDateFormat2 = new SimpleDateFormat(
				"yyyy-MM-dd", Locale.ENGLISH);
		try {
			String str1 = localSimpleDateFormat2.format(localSimpleDateFormat1
					.parse(paramString));
			SimpleDateFormat localSimpleDateFormat3 = new SimpleDateFormat(
					"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.ENGLISH);
			localSimpleDateFormat3.setTimeZone(TimeZone.getTimeZone("GMT"));
			Date localDate = Calendar.getInstance(TimeZone.getTimeZone("GMT"),
					Locale.ENGLISH).getTime();
			// localDate.getTime().substring(0, 10);
			localDate.getTime();
			String str2 = localSimpleDateFormat3.format(localDate);

			String str3 = str1
					+ str2.substring(str2.indexOf("T"), str2.length());
			return str3;
		} catch (ParseException localParseException) {
			localParseException.printStackTrace();
		}
		return paramString;
	}

	public static String getGMTParsedDate(String paramString) {
		String str = paramString.substring(0, paramString.indexOf("T"));
		SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat(
				"yyyy-MM-dd", Locale.ENGLISH);
		try {
			str = localSimpleDateFormat
					.format(localSimpleDateFormat.parse(str));
			System.out.println(localSimpleDateFormat
					.format(localSimpleDateFormat.parse(str)));
			return str;
		} catch (ParseException localParseException) {
			while (true)
				localParseException.printStackTrace();
		}
	}

	public static String getGMTParsedDateAtt(String paramString) {
		String str = paramString.substring(0, paramString.indexOf("T"));
		SimpleDateFormat localSimpleDateFormat1 = new SimpleDateFormat(
				"yyyy-MM-dd", Locale.ENGLISH);
		SimpleDateFormat localSimpleDateFormat2 = new SimpleDateFormat(
				"dd-MM-yyyy", Locale.ENGLISH);
		try {
			str = localSimpleDateFormat2.format(localSimpleDateFormat1
					.parse(str));
			System.out.println(localSimpleDateFormat2
					.format(localSimpleDateFormat1.parse(str)));
			return str;
		} catch (ParseException localParseException) {
			while (true)
				localParseException.printStackTrace();
		}
	}

	public static String getLastMonth() {
		int i = Calendar.getInstance().get(2);
		String str = String.valueOf(i);
		return str;
	}

	public static ArrayList<String> getYears() {
		ArrayList localArrayList = new ArrayList();
		int i = Calendar.getInstance().get(1);
		for (int j = 2010;; j++) {
			if (j > i) {
				Collections.sort(localArrayList, Collections.reverseOrder());
				return localArrayList;
			}
			localArrayList.add(Integer.toString(j));
		}
	}

	public static boolean isEmailValid(String paramString) {
		boolean bool = Pattern
				.compile("^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$", 2)
				.matcher(paramString).matches();
		int i = 0;
		if (bool)
			i = 1;
		return bool;
	}

	public static boolean isNumeric(String paramString) {
		try {
			Integer.parseInt(paramString);
			return true;
		} catch (NumberFormatException localNumberFormatException) {
		}
		return false;
	}

	public static boolean isNumericFloat(String paramString) {
		try {
			Float.parseFloat(paramString);
			return true;
		} catch (NumberFormatException localNumberFormatException) {
		}
		return false;
	}

	public static String isValidDate(String paramString) {
		Calendar localCalendar1 = Calendar.getInstance();
		int i = localCalendar1.get(1);
		int j = localCalendar1.get(2);
		int k = localCalendar1.get(5);
		String str1 = i + "-" + (j + 1) + "-" + k;
		String str2 = "";
		try {
			SimpleDateFormat localSimpleDateFormat1 = new SimpleDateFormat(
					"MM-dd-yyyy", Locale.ENGLISH);
			SimpleDateFormat localSimpleDateFormat2 = new SimpleDateFormat(
					"yyyy-MM-dd", Locale.ENGLISH);
			String str3 = localSimpleDateFormat2.format(localSimpleDateFormat1
					.parse(paramString));
			Date localDate1 = localSimpleDateFormat2.parse(str3);
			Date localDate2 = localSimpleDateFormat2.parse(str1);
			System.out.println(localSimpleDateFormat2.format(localDate1));
			System.out.println(localSimpleDateFormat2.format(localDate2));
			Calendar localCalendar2 = Calendar.getInstance();
			Calendar localCalendar3 = Calendar.getInstance();
			localCalendar2.setTime(localDate1);
			localCalendar3.setTime(localDate2);
			if (localCalendar2.after(localCalendar3)) {
				System.out.println("check_date is after current_date");
				str2 = "after_today";
			}
			if (localCalendar2.before(localCalendar3)) {
				System.out.println("check_date is before current_date");
				str2 = "before_today";
			}
			if (localCalendar2.equals(localCalendar3)) {
				System.out.println("check_date is equal current_date");
				str2 = "today";
			}
			return str2;
		} catch (ParseException localParseException) {
			localParseException.printStackTrace();
		}
		return str2;
	}

	public static boolean isValidUrl(String paramString) {
		try {
			new URL(paramString);
			return true;
		} catch (MalformedURLException localMalformedURLException) {
		}
		return false;
	}

	public static boolean testEmpty(String paramString) {
		if ((paramString == null) || (paramString.matches("^\\s*$")))
			do
				return true;
			while ((paramString.equalsIgnoreCase("null"))
					|| (paramString.contains("null")));
		return false;
	}

	public String getRandomNumber(int paramInt) {
		Random localRandom = new Random();
		StringBuilder localStringBuilder = new StringBuilder(paramInt);
		for (int i = 0;; i++) {
			if (i >= paramInt)
				return localStringBuilder.toString();
			localStringBuilder.append((char) (48 + localRandom.nextInt(10)));
		}
	}
}
